<?php
include_once "../inc/common.php";


// generate activatiecode
$code = generateWebshopActivatiecode();
	

//insert company query 
$query = "INSERT INTO ShopCompanies 
		(
			Name,		 	 	 	 	 	 	
			Address,		 	 	 	 	 	 	 
			Zipcode,			 	 	 	 	 	 	 
			City,			 	 	 	 	 	 	 
			CountryID
		) 
		VALUES 
		(
			'".str_replace("'","&#39;",$_POST['email'])."',
			'".str_replace("'","&#39;",$code)."',
			MD5('".str_replace("'","&#39;",$_POST['password'])."'),
			'".str_replace("'","&#39;",$_POST['bedrijfsnaam'])."',
			'".str_replace("'","&#39;",$_POST['contact'])."',
			'".str_replace("'","&#39;",$_POST['functie'])."',
			'".str_replace("'","&#39;",$_POST['adres'])."',
			'".str_replace("'","&#39;",$_POST['postcode'])."',
			'".str_replace("'","&#39;",$_POST['woonplaats'])."',
			'".str_replace("'","&#39;",$_POST['land'])."',
			'".str_replace("'","&#39;",$_POST['kvk'])."',
			'".str_replace("'","&#39;",$_POST['btw'])."'
		)";





// save to DB
$query = "INSERT INTO Customers (
				Email,		 	 	 	 	 	 	
				ActivatieCode,		 	 	 	 	 	 	 
				Password,			 	 	 	 	 	 	 
				Companie,			 	 	 	 	 	 	 
				Contact,			 	 	 	 	 	 	 
				Function,			 	 	 	 	 	 	 
				Address,			 	 	 	 	 	 	 
				Zipcode,			 	 	 	 	 	 	 
				City,	
				Country,		 	 	 	 	 	 	 
				KVK,			 	 	 	 	 	 	 
				BTW
			) VALUES (
				'".str_replace("'","&#39;",$_POST['email'])."',
				'".str_replace("'","&#39;",$code)."',
				MD5('".str_replace("'","&#39;",$_POST['password'])."'),
				'".str_replace("'","&#39;",$_POST['bedrijfsnaam'])."',
				'".str_replace("'","&#39;",$_POST['contact'])."',
				'".str_replace("'","&#39;",$_POST['functie'])."',
				'".str_replace("'","&#39;",$_POST['adres'])."',
				'".str_replace("'","&#39;",$_POST['postcode'])."',
				'".str_replace("'","&#39;",$_POST['woonplaats'])."',
				'".str_replace("'","&#39;",$_POST['land'])."',
				'".str_replace("'","&#39;",$_POST['kvk'])."',
				'".str_replace("'","&#39;",$_POST['btw'])."'
			)";

$_MySQL->runQuery($query);
	
// mail activatiecode
$message = "<html>\n<head>\n</head>\n<body>\n";
$message .= "\nBeste heer/mevrouw, <br>"; 
$message .= "\n<br>"; 
$message .= "\nJe bent aangemeld als webshop bij prijsgezocht.<br>"; 
$message .= "\nWij vragen u alleen nog om uw aanmelding te bevestigen. <br>"; 
$message .= "\n<br>"; 
$message .= "\n<a href=\"http://webshop.prijsgezocht.nl/webshopBevestigen.php?code=".$code."\">Klik hier om te bevestigen.</a><br>"; 
$message .= "\n<br>"; 
$message .= "\nBedankt voor je aanmelding en graag tot ziens op prijsgezocht.nl. <br>"; 
$message .= "\n<br>"; 
$message .= "\nMet vriendelijke groeten, <br>"; 
$message .= "\nPrijsgezocht</body></html>";
	
$subject = 'Bevestig uw aamelding bij prijsgezocht';
$from_mail = 'info@prijsgezocht.nl';
$from_name = 'Prijsgezocht';

$mail = new phpmailer;
$mail->IsMail(); // set mailer to use SMTP
$mail->From = $from_mail;
$mail->FromName = $from_name;
list($naam, $domein) = explode("@",$_POST['email']);
$mail->AddAddress($_POST['email'], $naam);
$mail->AddReplyTo($from_mail, $from_name);
$mail->IsHTML(true);    // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->Send();


echo "U bent geregistreerd.\nEr komt een activatie mail naar u toe";